﻿using System;

namespace Red.Toolkit.Profiler.Logic
{
    /// <summary>
    /// Graph node (binary tree) for accelerating graph drawing.
    /// </summary>
    public class GraphNode
    {
        public double value;
        public GraphNode Left;
        public GraphNode Right;

        public double Start;
        public double End;
        public double Split;

        // create leaf node
        public GraphNode( double x, double y )
        {
            Left = Right = null;
            Start = End = x;
            value = y;
        }

        // create internal node
        public GraphNode( GraphNode left, GraphNode right )
        {
            Left = left;
            Right = right;
            Start = Math.Min( left.Start, right.Start );
            End = Math.Max( left.End, right.End );
            Split = (left.End + right.Start) / 2.0;
            value = (left.value + right.value) / 2.0; // simple average
        }
    }
}
